home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / MultiSelect.c < prev    next >
C/C++ Source or Header  |  2000-05-09  |  12KB  |  228 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/MultiSelect.c,v 41.11 2000/05/09 20:33:52 mlemos Exp $
  3.  *
  4.  * MultiSelect.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: MultiSelect.c,v $
  12.  * Revision 41.11  2000/05/09 20:33:52  mlemos
  13.  * Bumped to revision 41.11
  14.  *
  15.  * Revision 1.2  2000/05/09 19:59:08  mlemos
  16.  * Merged with the branch Manuel_Lemos_fixes.
  17.  *
  18.  * Revision 1.1.2.3  1998/12/07 00:14:09  mlemos
  19.  * Made the listview be activated by the key indicated in the added label.
  20.  *
  21.  * Revision 1.1.2.2  1998/03/01 19:45:41  mlemos
  22.  * Fixed the display of empty lines.
  23.  *
  24.  * Revision 1.1.2.1  1998/02/28 17:45:38  mlemos
  25.  * Ian sources
  26.  *
  27.  *
  28.  */
  29.  
  30. /* Execute me to compile with DICE V3.0
  31. dcc MultiSelect.c -proto -mi -ms -mRR -lbgui
  32. quit
  33. */
  34.  
  35. #include "DemoCode.h"
  36.  
  37. /*
  38. **      The entries shown in the list.
  39. **/
  40. UBYTE   *ListEntries[] = {
  41.         ISEQ_C "This listview object has multi-",
  42.         ISEQ_C "selection turned on. You can",
  43.         ISEQ_C "multi-select the items by holding",
  44.         ISEQ_C "down the SHIFT-key while clicking",
  45.         ISEQ_C "on the different items or by clicking",
  46.         ISEQ_C "on an entry and dragging the mouse",
  47.         ISEQ_C "up or down.",
  48.         "",
  49.         ISEQ_C "If you check the \"No SHIFT\" checbox",
  50.         ISEQ_C "you can multi-select the items without",
  51.         ISEQ_C "using the SHIFT key",
  52.         NULL
  53. };
  54.  
  55. /*
  56. **      Map-list.
  57. **/
  58. struct TagItem CheckToList[] = { GA_Selected, LISTV_MultiSelectNoShift, TAG_END };
  59.  
  60. /*
  61. **      Object ID's.
  62. **/
  63. #define ID_SHOW                 1
  64. #define ID_QUIT                 2
  65. #define ID_ALL                  3
  66. #define ID_NONE                 4
  67.  
  68. VOID StartDemo( void )
  69. {
  70.         struct Window           *window;
  71.         Object                  *WO_Window, *GO_Quit, *GO_Show, *GO_List, *GO_Shift, *GO_All, *GO_None;
  72.         ULONG                    signal, rc, tmp = 0;
  73.         BOOL                     running = TRUE;
  74.  
  75.         /*
  76.          *      Create the window object.
  77.          */
  78.         WO_Window = WindowObject,
  79.                 WINDOW_Title,           "Multi-Selection Demo",
  80.                 WINDOW_AutoAspect,      TRUE,
  81.                 WINDOW_SmartRefresh,    TRUE,
  82.                 WINDOW_RMBTrap,         TRUE,
  83.                 WINDOW_ScaleWidth,      30,
  84.                 WINDOW_ScaleHeight,     30,
  85.                 WINDOW_MasterGroup,
  86.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  87.                                 StartMember,
  88.                                         VGroupObject, HOffset( 4 ), VOffset( 4 ),
  89.                                                 FRM_Type,               FRTYPE_BUTTON,
  90.                                                 FRM_Recessed,           TRUE,
  91.                                                 StartMember,
  92.                                                         GO_List = ListviewObject,
  93.                                                                 LISTV_EntryArray,               ListEntries,
  94.                                                                 LISTV_MultiSelect,              TRUE,
  95.                                                                 Label("Se_lect next entry"),
  96.                                                                 Place(PLACE_ABOVE),
  97.                                                         EndObject,
  98.                                                 EndMember,
  99.                                                 StartMember,
  100.                                                         HGroupObject,
  101.                                                                 StartMember, GO_All  = KeyButton( "_All",  ID_ALL  ), EndMember,
  102.                                                                 StartMember, GO_None = KeyButton( "N_one", ID_NONE ), EndMember,
  103.                                                         EndObject, FixMinHeight,
  104.                                                 EndMember,
  105.                                         EndObject,
  106.                                 EndMember,
  107.                                 StartMember,
  108.                                         HGroupObject, HOffset( 4 ), VOffset( 4 ),
  109.                                                 FRM_Type,               FRTYPE_BUTTON,
  110.                                                 FRM_Recessed,           TRUE,
  111.                                                 VarSpace( DEFAULT_WEIGHT ),
  112.                                                 StartMember, GO_Shift = KeyCheckBox( "_No SHIFT:", FALSE, 0 ), EndMember,
  113.                                                 VarSpace( DEFAULT_WEIGHT ),
  114.                                         EndObject, FixMinHeight,
  115.                                 EndMember,
  116.                                 StartMember,
  117.                                         HGroupObject, Spacing( 4 ),
  118.                                                 StartMember, GO_Show = KeyButton( "_Show", ID_SHOW ), EndMember,
  119.                                                 VarSpace( DEFAULT_WEIGHT ),
  120.                                                 StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  121.                                         EndObject, FixMinHeight,
  122.                                 EndMember,
  123.                         EndObject,
  124.         EndObject;
  125.  
  126.         /*
  127.         **      Object created OK?
  128.         **/
  129.         if ( WO_Window ) {
  130.                 /*
  131.                 **      Assign the keys to the buttons.
  132.                 **/
  133.                 tmp += GadgetKey( WO_Window, GO_Quit,  "q" );
  134.                 tmp += GadgetKey( WO_Window, GO_Show,  "s" );
  135.                 tmp += GadgetKey( WO_Window, GO_Shift, "n" );
  136.                 tmp += GadgetKey( WO_Window, GO_All,   "a" );
  137.                 tmp += GadgetKey( WO_Window, GO_None,  "o" );
  138.                 tmp += GadgetKey( WO_Window, GO_List,  "l" );
  139.                 /*
  140.                 **      OK?
  141.                 **/
  142.                 if ( tmp == 6 ) {
  143.                         /*
  144.                         **      Add notification.
  145.                         **/
  146.                         if ( AddMap( GO_Shift, GO_List, CheckToList )) {
  147.                                 /*
  148.                                 **      try to open the window.
  149.                                 **/
  150.                                 if ( window = WindowOpen( WO_Window )) {
  151.                                         /*
  152.                                         **      Obtain it's wait mask.
  153.                                         **/
  154.                                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  155.                                         /*
  156.                                         **      Event loop...
  157.                                         **/
  158.                                         do {
  159.                                                 Wait( signal );
  160.                                                 /*
  161.                                                 **      Handle events.
  162.                                                 **/
  163.                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  164.                                                         /*
  165.                                                         **      Evaluate return code.
  166.                                                         **/
  167.                                                         switch ( rc ) {
  168.  
  169.                                                                 case    WMHI_CLOSEWINDOW:
  170.                                                                 case    ID_QUIT:
  171.                                                                         running = FALSE;
  172.                                                                         break;
  173.  
  174.                                                                 case    ID_ALL:
  175.                                                                         SetGadgetAttrs(( struct Gadget * )GO_List, window, NULL, LISTV_SelectMulti, LISTV_Select_All, TAG_END );
  176.                                                                         break;
  177.  
  178.                                                                 case    ID_NONE:
  179.                                                                         SetGadgetAttrs(( struct Gadget * )GO_List, window, NULL, LISTV_DeSelect, ~0, TAG_END );
  180.                                                                         break;
  181.  
  182.                                                                 case    ID_SHOW:
  183.                                                                 {
  184.                                                                         UBYTE           *str;
  185.  
  186.                                                                         /*
  187.                                                                         **      Simply dump all selected entries
  188.                                                                         **      to the console.
  189.                                                                         **/
  190.                                                                         if ( str = ( UBYTE * )FirstSelected( GO_List )) {
  191.                                                                                 do {
  192.                                                                                         STRPTR text=str;
  193.  
  194.                                                                                         if(*text)
  195.                                                                                           text++;
  196.                                                                                         if(*text)
  197.                                                                                           text++;
  198.                                                                                         Tell( "%s\n", text);
  199.                                                                                         str = ( UBYTE * )NextSelected( GO_List, str );
  200.                                                                                 } while ( str );
  201.                                                                         } else
  202.                                                                                 /*
  203.                                                                                 **      Oops. There are no selected
  204.                                                                                 **      entries.
  205.                                                                                 **/
  206.                                                                                 Tell( "No selections made!\n" );
  207.                                                                         break;
  208.                                                                 }
  209.                                                         }
  210.                                                 }
  211.                                         } while ( running );
  212.                                 } else
  213.                                         Tell( "Could not open the window\n" );
  214.                         } else
  215.                                 Tell( "Unable to add notification\n" );
  216.                 } else
  217.                         Tell( "Could not assign gadget keys\n" );
  218.                 /*
  219.                 **      Disposing of the window object will
  220.                 **      also close the window if it is
  221.                 **      already opened and it will dispose of
  222.                 **      all objects attached to it.
  223.                 **/
  224.                 DisposeObject( WO_Window );
  225.         } else
  226.                 Tell( "Could not create the window object\n" );
  227. }
  228.